package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Window.Type;
import net.miginfocom.swing.MigLayout;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JSeparator;

import controlLayer.TableCtr;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class SettingsGui extends JFrame {

	//ctr vars
	private TableCtr tableCtr = new TableCtr();
	///
	private JPanel contentPane;

	/**
	 * Create the frame.
	 */
	public SettingsGui() {
		setTitle("Settings");
		setType(Type.UTILITY);
		setAlwaysOnTop(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new MigLayout("", "[][]", "[][][][][][][][][][][]"));
		
		JLabel lblDatabaseSettings = new JLabel("Database Settings");
		contentPane.add(lblDatabaseSettings, "cell 0 0 2 1");
		
		JSeparator separator = new JSeparator();
		contentPane.add(separator, "cell 0 1 2 1,growx");
		
		JLabel lblCheckIfDatabase = new JLabel("Check if database is valid:");
		contentPane.add(lblCheckIfDatabase, "cell 0 2,alignx left");
		
		JButton btnCheck = new JButton("Check");
		btnCheck.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			}
		});
		contentPane.add(btnCheck, "cell 1 2,growx");
		
		JLabel lblExportCurrentDatabasebackup = new JLabel("Export current database(backup):");
		contentPane.add(lblExportCurrentDatabasebackup, "cell 0 3,alignx left");
		
		JButton btnExport = new JButton("Export");
		contentPane.add(btnExport, "cell 1 3,growx");
		
		JLabel lblImportADatabase = new JLabel("Import a database file(backup):");
		contentPane.add(lblImportADatabase, "cell 0 4,alignx left");
		
		JButton btnImport = new JButton("Import");
		contentPane.add(btnImport, "cell 1 4,growx");
		
		JSeparator separator_1 = new JSeparator();
		contentPane.add(separator_1, "cell 0 5 2 1,growx");
		
		JSeparator separator_2 = new JSeparator();
		contentPane.add(separator_2, "cell 0 7 2 1,growx");
		
		JLabel lblDestroyTables = new JLabel("Destroy Tables:");
		contentPane.add(lblDestroyTables, "cell 0 8,alignx left");
		
		JButton btnDestroy = new JButton("Destroy");
		btnDestroy.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					int e1 = tableCtr.dropAllTables();
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		contentPane.add(btnDestroy, "cell 1 8,growx");
		
		JLabel lblGenerateTables = new JLabel("Generate Tables:");
		contentPane.add(lblGenerateTables, "cell 0 9,alignx left");
		
		JButton btnGenerate = new JButton("Generate");
		btnGenerate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					int e1 = tableCtr.createAllTables();
				} catch (Exception e1) {
					e1.printStackTrace();
				}
			}
		});
		contentPane.add(btnGenerate, "cell 1 9,growx");
		
		JSeparator separator_3 = new JSeparator();
		contentPane.add(separator_3, "cell 0 10 2 1,growx");
	}

}
